package com.mysteel.order.vo;

import com.mysteel.common.to.SkuHasStockTo;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * ProjectName: mail
 * ClassName: OrderConfirmVo
 * Description:订单确认页数据模型
 * date: 2021/03/20/020 14:40
 *
 * @author xiaochao
 */
public class OrderConfirmVo {

    /**
     * 用户收货地址信息
     */
    private List<MemberAddressVo> address;

    /**
     * 所选中的所有购物项
     */
    private List<OrderItemVo> items;

    /**
     * 商品是否有库存
     */
    private Map<Long,Boolean> stocks;

    /**
     * 用户积分信息
     */
    private Integer integration;

    /**
     * 订单总额
     */
    private BigDecimal totalPrice;

    /**
     * 应付金额
     */
    private BigDecimal payPrice;

    /**
     * TODO 防重复提交令牌
     */
    private String orderToken;

    public List<MemberAddressVo> getAddress() {
        return address;
    }

    public void setAddress(List<MemberAddressVo> address) {
        this.address = address;
    }

    public List<OrderItemVo> getItems() {
        return items;
    }

    public void setItems(List<OrderItemVo> items) {
        this.items = items;
    }

    public Integer getIntegration() {
        return integration;
    }

    public void setIntegration(Integer integration) {
        this.integration = integration;
    }

    public BigDecimal getTotalPrice() {
        BigDecimal sum = new BigDecimal(0);
        if (!CollectionUtils.isEmpty(items)){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }


    public BigDecimal getPayPrice() {
       return getTotalPrice();
    }

    public String getOrderToken() {
        return orderToken;
    }

    public void setOrderToken(String orderToken) {
        this.orderToken = orderToken;
    }

    public Integer getTotalCount(){
        Integer totalCount = 0;
        if (!CollectionUtils.isEmpty(items)){
            for (OrderItemVo item : items) {
                totalCount += item.getCount();
            }
        }
        return totalCount;
    }

    public Map<Long, Boolean> getStocks() {
        return stocks;
    }

    public void setStocks(Map<Long, Boolean> stocks) {
        this.stocks = stocks;
    }
}
